#ifndef IMAGECREATOR_H
#define IMAGECREATOR_H

#include "common/symbol.h"
#include "pictureinfo.h"

#include <QImage>
#include <vector>
#include <QColor>

namespace qrcode {

//typedef std::vector<std::vector<char>> msgbits;

class ImageCreator
{
private:
    std::vector<char> bitstream;

    int nPix; //生成图片的默认像素大小
    int nMods;  //当前版本每边的模块数
    int version;  //版本
    char errorLevel;

    PictureInfo pic;
    //图片相关设置
//    int COE;  //像素系数
//    std::string filepath;  //图片存放路径
//    std::string filename;  //图片名称
//    std::string picFormat; //图片格式

    //QImage image;

    std::vector<std::vector<int>> coordinatesAlignPatterns;  //矫正图形中心模块的行/列坐标值
    std::vector<std::pair<int, int>> lockModule;

    void init();

    QImage GenPicture(QImage &image, int coe);
    void DrawSquarePix(QImage &image, QColor color, int x, int y, int coe);

    QImage BaseModuleMatrix();
    void AddFinderPatterns(QImage &image, int &nMods);
    void AddAlignmentPatterns(QImage &image, int &version);
    void AddTimingPatterns(QImage &image);
    void AddReservedAreas(QImage &image);
    void DrawAlignmentPatterns(QImage &image, int &x, int &y);
    void AddFormatInfo(QImage &image, std::vector<int> info);
    void AddVersionInfo(QImage &image, std::vector<int> info);

    void PlaceDataBits(QImage &image);

    bool WithinFinderPatterns(int x, int y);
    bool IsLockModule(int x, int y);

    void DrawPixelColor(QImage &image, int x, int y, int n);
    void DrawPixelColor(QImage &image, std::vector<int> &info, int n, int x, int y);

public:
    ImageCreator();
    ImageCreator(int version, std::vector<char> bitstream);
    QImage GeneratorPixelImg();
    void Creator();

    std::vector<std::pair<int, int>> GetLockModule(int v);

    void setErrorLevel(char value);
    void setPic(const PictureInfo &value);
    void setVersion(int value);
};

}

#endif // IMAGECREATOR_H
